package
{
	import LoaderTexture;
	import alternativa.engine3d.core.Mesh;
	import alternativa.engine3d.materials.FillMaterial;
	import alternativa.engine3d.materials.WireMaterial;
	import alternativa.engine3d.materials.TextureMaterial;
	import alternativa.types.Texture;
	import flash.display.BlendMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.utils.Timer;
	
	import alternativa.engine3d.core.Surface;
	import alternativa.types.Point3D;
	
	import alternativa.engine3d.core.Object3D;
	
	public class Couloir extends Mesh
	{
		private var hauteur:int;
		private var largeur:int;
		private var longueur:int;
		
		private var hPorte:int;
		private var lPorte:int;
		
		private var espacePetit:int;
		private var espaceGrand:int;
		
		private var hFenetre1:int;
		private var hFenetre2:int;
		private var hAscenseur:int;
		
		public function Couloir()
		{
			super(name);
			hauteur=300;
			largeur=500;
			longueur=3000;
				
			hPorte=250;
			lPorte=100;
			espaceGrand=700; // ((7/10)*(longueur/3)
			espacePetit=50;
			hFenetre1=100;
			hFenetre2=200;
			hAscenseur=200;
			
			var x:int=0;
			var y:int=0;
			//*******Points*********
			createVertex(x,y,0,1); //devant, côté salles LP
			createVertex(x,y,hauteur,2);
			
			x+=850;
			createVertex(x,y,0,3);
			createVertex(x,y,hPorte,4);
			createVertex(x,y,hauteur,5);
			
			x+=lPorte;
			createVertex(x,y,0,6);
			createVertex(x,y,hPorte,7);
			createVertex(x,y,hauteur,8);
			
			x+=espaceGrand;
			createVertex(x,y,0,9);
			createVertex(x,y,hPorte,10);
			createVertex(x,y,hauteur,11);
			
			x+=lPorte;
			createVertex(x,y,0,12);
			createVertex(x,y,hPorte,13);
			createVertex(x,y,hauteur,14);
			
			x+=2*(espacePetit);
			createVertex(x,y,0,15);
			createVertex(x,y,hPorte,16);
			createVertex(x,y,hauteur,17);
			
			x+=lPorte;
			createVertex(x,y,0,18);
			createVertex(x,y,hPorte,19);
			createVertex(x,y,hauteur,20);
			
			x+=espaceGrand;
			createVertex(x,y,0,21);
			createVertex(x,y,hPorte,22);
			createVertex(x,y,hauteur,23);
			
			x+=lPorte;
			createVertex(x,y,0,24);
			createVertex(x,y,hPorte,25);
			createVertex(x,y,hauteur,26);
			
			x+=2*(espacePetit);
			createVertex(x,y,0,27);
			createVertex(x,y,hPorte,28);
			createVertex(x,y,hauteur,29);
			
			x+=lPorte;
			createVertex(x,y,0,30);
			createVertex(x,y,hPorte,31);
			createVertex(x,y,hauteur,32);
			
			x+=espaceGrand;
			createVertex(x,y,0,33);
			createVertex(x,y,hPorte,34);
			createVertex(x,y,hauteur,35);
			
			x+=lPorte;
			createVertex(x,y,0,36);
			createVertex(x,y,hPorte,37);
			createVertex(x,y,hauteur,38); // fin porte salle LP Asrall
			
			x+=200;
			createVertex(x,y,0,39);
			createVertex(x,y,hauteur,40);
			
			y+=largeur/10;
			createVertex(x,y,0,41);
			createVertex(x,y,hauteur,42);

			x+=50;
			createVertex(x,y,0,43);
			createVertex(x,y,hauteur,44);
			
			y-=largeur/10;
			createVertex(x,y,0,45);
			createVertex(x,y,hauteur,46);

			x+=150;
			createVertex(x,y,0,47);
			createVertex(x,y,hauteur,48);
			
			y-=500;
			createVertex(x,y,0,49);
			createVertex(x,y,hauteur,50);

			x+=100;
			createVertex(x,y,0,51);
			createVertex(x,y,hFenetre1,52);
			createVertex(x,y,hFenetre2,53);
			createVertex(x,y,hauteur,54);
			
			x+=300;
			createVertex(x,y,0,55);
			createVertex(x,y,hFenetre1,56);
			createVertex(x,y,hFenetre2,57);
			createVertex(x,y,hauteur,58);

			x+=100;
			createVertex(x,y,0,59);
			createVertex(x,y,hauteur,60);

			y+=200;//ascenseur1
			createVertex(x,y,0,61);
			createVertex(x,y,hAscenseur,62);
			createVertex(x,y,hauteur,63);
			
			y+=lPorte;
			createVertex(x,y,0,64);
			createVertex(x,y,hAscenseur,65);
			createVertex(x,y,hauteur,66);
			
			y+=100;//assenceur2
			createVertex(x,y,0,67);
			createVertex(x,y,hAscenseur,68);
			createVertex(x,y,hauteur,69);
			
			y+=lPorte;
			createVertex(x,y,0,70);
			createVertex(x,y,hAscenseur,71);
			createVertex(x,y,hauteur,72);
			
			y+=200;//Double-porte escaliers
			createVertex(x,y,0,73);
			createVertex(x,y,hPorte,74);
			createVertex(x,y,hauteur,75);
			
			y+=lPorte*2;
			createVertex(x,y,0,76);
			createVertex(x,y,hPorte,77);
			createVertex(x,y,hauteur,78);
			
			y+=2*espacePetit;
			createVertex(x,y,0,79);
			createVertex(x,y,hauteur,80);
			
			x-=200;
			createVertex(x,y,0,81);
			createVertex(x,y,hPorte,82);
			createVertex(x,y,hauteur,83);
			
			x-=lPorte;
			createVertex(x,y,0,84);
			createVertex(x,y,hPorte,85);
			createVertex(x,y,hauteur,86);
			
			x-=200;
			createVertex(x,y,0,870);
			createVertex(x,y,hauteur,880);
			
			x-=150;
			createVertex(x,y,0,87);
			createVertex(x,y,hauteur,88);
			
			y-=largeur/10;
			createVertex(x,y,0,89);
			createVertex(x,y,hauteur,90);
			
			x-=50;
			createVertex(x,y,0,91);
			createVertex(x,y,hauteur,92)
			
			y+=largeur/10;
			createVertex(x,y,0,93);
			createVertex(x,y,hauteur,94);

			x-=200;// debut porte salles non LP
			createVertex(x,y,0,95); 
			createVertex(x,y,hPorte,96);
			createVertex(x,y,hauteur,97);
			
			x-=lPorte;
			createVertex(x,y,0,98);
			createVertex(x,y,hPorte,99);
			createVertex(x,y,hauteur,100);
			
			x-=1300;
			createVertex(x,y,0,101);
			createVertex(x,y,hPorte,102);
			createVertex(x,y,hauteur,103);
			
			x-=lPorte;
			createVertex(x,y,0,104);
			createVertex(x,y,hPorte,105);
			createVertex(x,y,hauteur,106);
			
			x-=2*espacePetit;
			createVertex(x,y,0,107);
			createVertex(x,y,hPorte,108);
			createVertex(x,y,hauteur,109);
			
			x-=lPorte;
			createVertex(x,y,0,110);
			createVertex(x,y,hPorte,111);
			createVertex(x,y,hauteur,112);
			
			x-=1300;
			createVertex(x,y,0,113);
			createVertex(x,y,hPorte,114);
			createVertex(x,y,hauteur,115);
			
			x-=lPorte;
			createVertex(x,y,0,116);
			createVertex(x,y,hPorte,117);
			createVertex(x,y,hauteur,118);

			x-=650;
			createVertex(x,y,0,119);
			createVertex(x,y,hauteur,120);
			
			y-=150;
			createVertex(x,y,0,121);
			createVertex(x,y,hPorte,122);
			createVertex(x,y,hauteur,123);
			
			y-=2*lPorte;
			createVertex(x,y,0,124);
			createVertex(x,y,hPorte,125);
			createVertex(x,y,hauteur,126);
			
			
			//*********Faces*********
			createFace([1,2,5,3],"Fcd1"); // Fcd : faces côté devant (salles LP)
			setUVsToFace(new Point(2, 0), new Point(2, 1), new Point(0, 1), "Fcd1");
			createFace([4,5,8,7],"Fcd2");
			setUVsToFace(new Point(0.6, 0.33), new Point(0.6, 0.66), new Point(0.4, 0.66), "Fcd2");
			createFace([6,8,11,9],"Fcd3");
			setUVsToFace(new Point(2, 0), new Point(2, 1), new Point(0, 1), "Fcd3");
			createFace([10,11,14,13],"Fcd4");
			setUVsToFace(new Point(0.6, 0.33), new Point(0.6, 0.66), new Point(0.4, 0.66), "Fcd4");
			createFace([12,14,17,15],"Fcd5");
			setUVsToFace(new Point(0.6, 0), new Point(0.6, 1), new Point(0.4, 1), "Fcd5");
			createFace([16,17,20,19],"Fcd6");
			setUVsToFace(new Point(0.6, 0.33), new Point(0.6, 0.66), new Point(0.4, 0.66), "Fcd6");
			createFace([18,20,23,21],"Fcd7");
			setUVsToFace(new Point(2, 0), new Point(2, 1), new Point(0, 1), "Fcd7");
			createFace([22,23,26,25],"Fcd8");
			setUVsToFace(new Point(0.6, 0.33), new Point(0.6, 0.66), new Point(0.4, 0.66), "Fcd8");
			createFace([24,26,29,27],"Fcd9");
			setUVsToFace(new Point(0.6, 0), new Point(0.6, 1), new Point(0, 1), "Fcd9");
			createFace([28,29,32,31],"Fcd10");
			setUVsToFace(new Point(0.6, 0.33), new Point(0.6, 0.66), new Point(0.4, 0.66), "Fcd10");
			createFace([30,32,35,33],"Fcd11");
			setUVsToFace(new Point(2, 0), new Point(2, 1), new Point(0, 1), "Fcd11");
			createFace([34,35,38,37],"Fcd12");
			setUVsToFace(new Point(0.6, 0.33), new Point(0.6, 0.66), new Point(0.4, 0.66), "Fcd12");
			createFace([36,38,40,39],"Fcd13");
			setUVsToFace(new Point(0.6, 0), new Point(0.6, 1), new Point(0, 1), "Fcd13");
			createFace([39,40,42,41],"Fcd14");
			setUVsToFace(new Point(0.6, 0), new Point(0.6, 1), new Point(0.4, 1), "Fcd14");
			
			createFace([41,42,44,43],"Fcj1");
			setUVsToFace(new Point(0.6, 0), new Point(0.6, 1), new Point(0.4, 1), "Fcj1");
			
			createFace([43,44,46,45],"Fe1"); //Fe : faces dans l'entrée
			setUVsToFace(new Point(1, 0), new Point(1, 1), new Point(0, 1), "Fe1");
			createFace([45,46,48,47],"Fe2");
			setUVsToFace(new Point(1, 0), new Point(1, 1), new Point(0, 1), "Fe2");
			createFace([47,48,50,49],"Fe3");
			setUVsToFace(new Point(1, 0), new Point(1, 1), new Point(0, 1), "Fe3");
			createFace([49,50,54,51],"Fe4");
			setUVsToFace(new Point(0.6, 0), new Point(0.6, 1), new Point(0.4, 1), "Fe4");
			createFace([51,52,56,55],"Fe5");
			setUVsToFace(new Point(1, 0), new Point(1, 0.33), new Point(0, 0.33), "Fe5");
			createFace([53,54,58,57],"Fe6");
			setUVsToFace(new Point(1, 0.66), new Point(1, 1), new Point(0, 1), "Fe6");
			createFace([55,58,60,59],"Fe7");
			setUVsToFace(new Point(1, 0), new Point(1, 1), new Point(0, 1), "Fe7");
			createFace([59,60,63,61],"Fe8");
			setUVsToFace(new Point(1, 0), new Point(1, 1), new Point(0, 1), "Fe8");
			createFace([62,63,66,65],"Fe9");
			setUVsToFace(new Point(1, 0.66), new Point(1, 1), new Point(0, 1), "Fe9");
			createFace([64,66,69,67],"Fe10");
			setUVsToFace(new Point(1, 0), new Point(1, 1), new Point(0, 1), "Fe10");
			createFace([68,69,72,71],"Fe11");
			setUVsToFace(new Point(1, 0.66), new Point(1, 1), new Point(0, 1), "Fe11");
			createFace([70,72,75,73],"Fe12");
			setUVsToFace(new Point(0.5, 0), new Point(0.5, 1), new Point(0, 1), "Fe12");
			createFace([74,75,78,77],"Fe13");
			setUVsToFace(new Point(0.5, 0.66), new Point(0.5, 1), new Point(0, 1), "Fe13");
			createFace([76,78,80,79],"Fe14");
			setUVsToFace(new Point(0.5, 0), new Point(0.5, 1), new Point(0, 1), "Fe14");
			createFace([79,80,83,81],"Fe15");
			setUVsToFace(new Point(0.5, 0), new Point(0.5, 1), new Point(0, 1), "Fe15");
			createFace([82,83,86,85],"Fe16");
			setUVsToFace(new Point(0.5, 0.66), new Point(0.5, 1), new Point(0, 1), "Fe16");
			createFace([84,86,88,87],"Fe17");
			setUVsToFace(new Point(0.5, 0), new Point(0.5, 1), new Point(0, 1), "Fe17");
			createFace([87,88,90,89],"Fe18");
			setUVsToFace(new Point(0.5, 0), new Point(0.5, 1), new Point(0, 1), "Fe18");

			createFace([89,90,92,91],"Fcj2");
			setUVsToFace(new Point(0.6, 0), new Point(0.6, 1), new Point(0.4, 1), "Fcj2");
			
			createFace([91,92,94,93],"Fcb1"); // Fcb : faces côté derrière (salles NON-LP)
			setUVsToFace(new Point(0.6, 0), new Point(0.6, 1), new Point(0.4, 1), "Fcb1");
			createFace([93,94,97,95],"Fcb2");
			setUVsToFace(new Point(0.6, 0), new Point(0.6, 1), new Point(0.4, 1), "Fcb2");
			createFace([96,97,100,99],"Fcb3");
			setUVsToFace(new Point(0.6, 0.33), new Point(0.6, 0.66), new Point(0.4, 0.66), "Fcb3");
			createFace([98,100,103,101],"Fcb4");
			setUVsToFace(new Point(3.25, 0), new Point(3.25, 1), new Point(0, 1), "Fcb4");
			createFace([102,103,106,105],"Fcb5");
			setUVsToFace(new Point(0.6, 0.33), new Point(0.6, 0.66), new Point(0.4, 0.66), "Fcb5");
			createFace([104,106,109,107],"Fcb6");
			setUVsToFace(new Point(0.6, 0), new Point(0.6, 1), new Point(0.4, 1), "Fcb6");
			createFace([108,109,112,111],"Fcb7");
			setUVsToFace(new Point(0.6, 0.33), new Point(0.6, 0.66), new Point(0.4, 0.66), "Fcb7");
			createFace([110,112,115,113],"Fcb8");
			setUVsToFace(new Point(3.25, 0), new Point(3.25, 1), new Point(0, 1), "Fcb8");
			createFace([114,115,118,117],"Fcb9");
			setUVsToFace(new Point(0.6, 0.33), new Point(0.6, 0.66), new Point(0.4, 0.66), "Fcb9");
			createFace([116,118,120,119],"Fcb10");
			setUVsToFace(new Point(1.625, 0), new Point(1.625, 1), new Point(0, 1), "Fcb10");
			createFace([119,120,123,121],"Fcb11");
			setUVsToFace(new Point(0.375, 0), new Point(0.375, 1), new Point(0, 1), "Fcb11");
			createFace([122,123,126,125],"Fcb12");
			setUVsToFace(new Point(0.5, 0.33), new Point(0.5, 0.66), new Point(0, 0.66), "Fcb12");
			createFace([124,126,2,1],"Fcb13");
			setUVsToFace(new Point(0.375, 0), new Point(0.375, 1), new Point(0, 1), "Fcb13");
			
			//inv
			createFace([73,75,72,70],"Fe12i");
			createFace([77,78,75,74],"Fe13i");
			createFace([79,80,78,76],"Fe14i");
			
			//portes fermées
			createFace([81,82,85,84],"Ferme1");
			setUVsToFace(new Point(1, 0), new Point(1, 1), new Point(0, 1), "Ferme1");
			createFace([121,122,125,124],"Ferme2");
			setUVsToFace(new Point(1, 0), new Point(1, 1), new Point(0, 1), "Ferme2");
			
			createFace([2,120,880,48],"Fp1"); // Ft : faces plafond
			setUVsToFace(new Point(25, 0.6), new Point(25, 5.5), new Point(0, 5.5), "Fp1");
			createFace([50,880,80,60],"Fp2");
			setUVsToFace(new Point(4, 0.6), new Point(4, 10.528), new Point(0, 10.528), "Fp2");
			
			createFace([1,47,870,119],"Fs1"); // Fs : faces sol
			createFace([49,59,79,870],"Fs2");
			
			//*******Surfaces*******
			createSurface(["Fcd1","Fcd2","Fcd3","Fcd4","Fcd5","Fcd6","Fcd7","Fcd8","Fcd9","Fcd10","Fcd11","Fcd12","Fcd13","Fcd14","Fcj1"], "mursCD");
			createSurface(["Fcb1","Fcb2","Fcb3","Fcb4","Fcb5","Fcb6","Fcb7","Fcb8","Fcb9","Fcb10","Fcb11","Fcb12","Fcb13","Fcj2"], "mursCB");
			createSurface(["Fe1","Fe2","Fe3","Fe4","Fe5","Fe6","Fe7","Fe8","Fe9","Fe10","Fe11","Fe12","Fe13","Fe14","Fe15","Fe16","Fe17","Fe18"], "mursE");
			createSurface(["Fe12i","Fe13i","Fe14i"],"mursEscalier");
			createSurface(["Fp1","Fp2"], "plafond");
			createSurface(["Fs1","Fs2"], "sol");
			createSurface(["Ferme1"], "Ferme1");
			createSurface(["Ferme2"], "Ferme2");
			
			//*******Texturage*******
			//setWireMaterials();
			//setFillMaterials();
			setTextureMaterials();
			
		}
		private function setWireMaterials():void {
			moveAllFacesToSurface("temp");
			setMaterialToSurface(new WireMaterial(1, 0xFF0000),"temp");
		}
		
		private function setFillMaterials():void {
			moveAllFacesToSurface("temp");
			setMaterialToSurface(new FillMaterial(0xAABBCC,1,"normal",1,0x000000),"temp");
		}
		
		private function setTextureMaterials():void {
			var tm1:TextureMaterial=new TextureMaterial(LoaderTexture.getTexture("mur"), 1, true, true, BlendMode.NORMAL, -1, 0x000000, 3);
			var tm2:TextureMaterial=new TextureMaterial(LoaderTexture.getTexture("mur"), 1, true, true, BlendMode.NORMAL, -1, 0x000000, 3);
			var tm3:TextureMaterial=new TextureMaterial(LoaderTexture.getTexture("mur"), 1, true, true, BlendMode.NORMAL, -1, 0x000000, 3);
			setMaterialToSurface(tm1, "mursCD");
			setMaterialToSurface(tm2, "mursCB");
			setMaterialToSurface(tm3, "mursE");
			var tmp:TextureMaterial=new TextureMaterial(LoaderTexture.getTexture("plafond"), 1, true, true, BlendMode.NORMAL, -1, 0x000000, 3);
			setMaterialToSurface(tmp,"plafond");
			var tmf1:TextureMaterial=new TextureMaterial(LoaderTexture.getTexture("fermee1"), 1, true, true, BlendMode.NORMAL, -1, 0x000000, 3);
			setMaterialToSurface(tmf1, "Ferme1");
			var tmf2:TextureMaterial=new TextureMaterial(LoaderTexture.getTexture("fermee2"), 1, true, true, BlendMode.NORMAL, -1, 0x000000, 3);
			setMaterialToSurface(tmf2, "Ferme2");
			
			setMaterialToSurface(new FillMaterial(0xCCCCCC,1,"normal",-1,0xCCCCCC),"sol");
			setMaterialToSurface(new FillMaterial(0x888888,1,"normal",1,0x888888),"mursEscalier");
		}
		
	}
}